9a93cbe62acad080ca60f4e0d6edf16cd6a9474a,plugins/vcs/solutions/jetbrains.mps.vcs.mergedriver/source_gen/jetbrains/mps/vcs/mergedriver/SvnInstaller.java,SvnInstaller,install,#Project#,23
Before Change
return;
}
if (!(configFile.canWrite()) && configFile.getParentFile().canWrite()) {
Messages.showErrorDialog(project, "Can't write to Subversion config (~/.subversion).", "Can't Write");
return;
}
After Change
if (!(dryRun)) {
Messages.showErrorDialog(myProject, "Could not find Subversion configuration file (~/.subversion/config).", "Subversion Config Not Found");
}
return AbstractInstaller.State.NOT_INSTALLED;
}
if (!(myConfigFile.canWrite()) && myConfigDir.canWrite()) {
if (!(dryRun)) {
Messages.showErrorDialog(myProject, "Can't write to Subversion config (~/.subversion).", "Can't Write");
}
return AbstractInstaller.State.NOT_INSTALLED;
}
String configLine = String.format("diff3-cmd = %s", getScriptFile());
List<String> lines = StringsIO.readLines(myConfigFile);
int lineToReplace = -1;
for (int i = 0; i < ListSequence.fromList(lines).count(); i++) {
String line = ListSequence.fromList(lines).getElement(i);
if (line.trim().startsWith("diff3-cmd")) {
// Some diff3 is already present
Matcher matcher = Pattern.compile("^\\s*diff3-cmd\\s*=\\s*(.+)$").matcher(line);
if (matcher.matches()) {
String cmd = matcher.group(1);
if (cmd.contains("mps-merger.")) {
// already installed
if (dryRun) {
if (eq_k2wvr2_a0a0c0c0d0b0h0a(line, configLine)) {
return AbstractInstaller.State.INSTALLED;
} else {
return AbstractInstaller.State.OUTDATED;
}
}
lineToReplace = i;
break;
} else {
// another is installed
// TODO integrate with user's merger
lineToReplace = i;
break;
}
}
}
}
if (lineToReplace == -1) {
String commented = ListSequence.fromList(lines).findFirst(new IWhereFilter<String>() {
public boolean accept(String line) {
return line.trim().startsWith("# diff3-cmd");
}
});
if (commented != null) {
lineToReplace = ListSequence.fromList(lines).indexOf(commented);
} else {
int helpersStart = ListSequence.fromList(lines).indexOf(ListSequence.fromList(lines).findFirst(new IWhereFilter<String>() {
public boolean accept(String line) {
return line.trim().equals("[helpers]");
}
}));
if (helpersStart != -1) {
// [helpers] section is present, finding next section start
int nextStart = ListSequence.fromList(lines).indexOf(ListSequence.fromList(lines).skip(helpersStart + 1).findFirst(new IWhereFilter<String>() {
public boolean accept(String line) {
return line.trim().startsWith("[");
}
}));
if (nextStart == -1) {
// [helpers] is the last section
ListSequence.fromList(lines).addElement("");
lineToReplace = ListSequence.fromList(lines).count() - 1;
} else {
Iterable<String> section = ListSequence.fromList(lines).page(helpersStart + 1, nextStart);
// Finding last non-comment line
int nonComment = Sequence.fromIterable(section).indexOf(Sequence.fromIterable(section).findLast(new IWhereFilter<String>() {
public boolean accept(String line) {
return !(line.trim().startsWith("#")) && !(line.trim().isEmpty());
}
}));
if (nonComment == -1) {
lineToReplace = helpersStart + 1;
} else {
lineToReplace = nonComment + helpersStart + 1;
}
ListSequence.fromList(lines).insertElement(lineToReplace, "");
}
}
}
}
AbstractInstaller.State createScriptResult = createScript(dryRun);
if (createScriptResult != AbstractInstaller.State.INSTALLED) {
return createScriptResult;
}
if (dryRun) {
return AbstractInstaller.State.NOT_INSTALLED;
}
if (lineToReplace == -1) {
ListSequence.fromList(lines).addElement("[helpers]");
ListSequence.fromList(lines).addElement(configLine);
} else {
ListSequence.fromList(lines).setElement(lineToReplace, configLine);
}
try {
StringsIO.writeLines(myConfigFile, lines);
Messages.showInfoMessage(myProject, "Successfully installed MPS merger for Subversion", "Subversion Merger Installed");
return AbstractInstaller.State.INSTALLED;
} catch (IOException e) {
Messages.showErrorDialog(myProject, "Could not update Subversion configuration file (~/.subversion/config)." + e.getMessage(), "Could Not Save Config");
return AbstractInstaller.State.NOT_INSTALLED;
}
}